/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package tfmcbs.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectWithInverseResolvingEList;
import org.eclipse.emf.ecore.util.InternalEList;

import tfmcbs.Dependency;
import tfmcbs.Entity;
import tfmcbs.TfmcbsPackage;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Entity</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link tfmcbs.impl.EntityImpl#getDependFrom <em>Depend From</em>}</li>
 *   <li>{@link tfmcbs.impl.EntityImpl#getDependTo <em>Depend To</em>}</li>
 *   <li>{@link tfmcbs.impl.EntityImpl#getExtends <em>Extends</em>}</li>
 *   <li>{@link tfmcbs.impl.EntityImpl#getChilds <em>Childs</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public abstract class EntityImpl extends ElementImpl implements Entity {
	/**
	 * The cached value of the '{@link #getDependFrom() <em>Depend From</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDependFrom()
	 * @generated
	 * @ordered
	 */
	protected EList<Dependency> dependFrom;

	/**
	 * The cached value of the '{@link #getDependTo() <em>Depend To</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDependTo()
	 * @generated
	 * @ordered
	 */
	protected EList<Dependency> dependTo;

	/**
	 * The cached value of the '{@link #getExtends() <em>Extends</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getExtends()
	 * @generated
	 * @ordered
	 */
	protected Entity extends_;

	/**
	 * The cached value of the '{@link #getChilds() <em>Childs</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getChilds()
	 * @generated
	 * @ordered
	 */
	protected EList<Entity> childs;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected EntityImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return TfmcbsPackage.Literals.ENTITY;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Dependency> getDependFrom() {
		if (dependFrom == null) {
			dependFrom = new EObjectWithInverseResolvingEList<Dependency>(Dependency.class, this, TfmcbsPackage.ENTITY__DEPEND_FROM, TfmcbsPackage.DEPENDENCY__TO);
		}
		return dependFrom;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Dependency> getDependTo() {
		if (dependTo == null) {
			dependTo = new EObjectWithInverseResolvingEList<Dependency>(Dependency.class, this, TfmcbsPackage.ENTITY__DEPEND_TO, TfmcbsPackage.DEPENDENCY__FROM);
		}
		return dependTo;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Entity getExtends() {
		if (extends_ != null && extends_.eIsProxy()) {
			InternalEObject oldExtends = (InternalEObject)extends_;
			extends_ = (Entity)eResolveProxy(oldExtends);
			if (extends_ != oldExtends) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, TfmcbsPackage.ENTITY__EXTENDS, oldExtends, extends_));
			}
		}
		return extends_;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Entity basicGetExtends() {
		return extends_;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetExtends(Entity newExtends, NotificationChain msgs) {
		Entity oldExtends = extends_;
		extends_ = newExtends;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, TfmcbsPackage.ENTITY__EXTENDS, oldExtends, newExtends);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setExtends(Entity newExtends) {
		if (newExtends != extends_) {
			NotificationChain msgs = null;
			if (extends_ != null)
				msgs = ((InternalEObject)extends_).eInverseRemove(this, TfmcbsPackage.ENTITY__CHILDS, Entity.class, msgs);
			if (newExtends != null)
				msgs = ((InternalEObject)newExtends).eInverseAdd(this, TfmcbsPackage.ENTITY__CHILDS, Entity.class, msgs);
			msgs = basicSetExtends(newExtends, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, TfmcbsPackage.ENTITY__EXTENDS, newExtends, newExtends));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Entity> getChilds() {
		if (childs == null) {
			childs = new EObjectWithInverseResolvingEList<Entity>(Entity.class, this, TfmcbsPackage.ENTITY__CHILDS, TfmcbsPackage.ENTITY__EXTENDS);
		}
		return childs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case TfmcbsPackage.ENTITY__DEPEND_FROM:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getDependFrom()).basicAdd(otherEnd, msgs);
			case TfmcbsPackage.ENTITY__DEPEND_TO:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getDependTo()).basicAdd(otherEnd, msgs);
			case TfmcbsPackage.ENTITY__EXTENDS:
				if (extends_ != null)
					msgs = ((InternalEObject)extends_).eInverseRemove(this, TfmcbsPackage.ENTITY__CHILDS, Entity.class, msgs);
				return basicSetExtends((Entity)otherEnd, msgs);
			case TfmcbsPackage.ENTITY__CHILDS:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getChilds()).basicAdd(otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case TfmcbsPackage.ENTITY__DEPEND_FROM:
				return ((InternalEList<?>)getDependFrom()).basicRemove(otherEnd, msgs);
			case TfmcbsPackage.ENTITY__DEPEND_TO:
				return ((InternalEList<?>)getDependTo()).basicRemove(otherEnd, msgs);
			case TfmcbsPackage.ENTITY__EXTENDS:
				return basicSetExtends(null, msgs);
			case TfmcbsPackage.ENTITY__CHILDS:
				return ((InternalEList<?>)getChilds()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case TfmcbsPackage.ENTITY__DEPEND_FROM:
				return getDependFrom();
			case TfmcbsPackage.ENTITY__DEPEND_TO:
				return getDependTo();
			case TfmcbsPackage.ENTITY__EXTENDS:
				if (resolve) return getExtends();
				return basicGetExtends();
			case TfmcbsPackage.ENTITY__CHILDS:
				return getChilds();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case TfmcbsPackage.ENTITY__DEPEND_FROM:
				getDependFrom().clear();
				getDependFrom().addAll((Collection<? extends Dependency>)newValue);
				return;
			case TfmcbsPackage.ENTITY__DEPEND_TO:
				getDependTo().clear();
				getDependTo().addAll((Collection<? extends Dependency>)newValue);
				return;
			case TfmcbsPackage.ENTITY__EXTENDS:
				setExtends((Entity)newValue);
				return;
			case TfmcbsPackage.ENTITY__CHILDS:
				getChilds().clear();
				getChilds().addAll((Collection<? extends Entity>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case TfmcbsPackage.ENTITY__DEPEND_FROM:
				getDependFrom().clear();
				return;
			case TfmcbsPackage.ENTITY__DEPEND_TO:
				getDependTo().clear();
				return;
			case TfmcbsPackage.ENTITY__EXTENDS:
				setExtends((Entity)null);
				return;
			case TfmcbsPackage.ENTITY__CHILDS:
				getChilds().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case TfmcbsPackage.ENTITY__DEPEND_FROM:
				return dependFrom != null && !dependFrom.isEmpty();
			case TfmcbsPackage.ENTITY__DEPEND_TO:
				return dependTo != null && !dependTo.isEmpty();
			case TfmcbsPackage.ENTITY__EXTENDS:
				return extends_ != null;
			case TfmcbsPackage.ENTITY__CHILDS:
				return childs != null && !childs.isEmpty();
		}
		return super.eIsSet(featureID);
	}

} //EntityImpl
